﻿<!DOCTYPE html>
<html>
	<head>
		<meta charset="gb2312">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0,user-scalable=no" id="viewport">
		<title>注册-迅泊达</title>
		<link rel="shortcut icon" href="favicon.ico"/>
		<link rel="stylesheet" href="css/base.css" />
		<link rel="stylesheet" type="text/css" href="css/register-phone.css"/>
		<link rel="stylesheet" href="font/fanhui/iconfont.css" />
		<script src="js/jquery-1.11.2.min.js"></script>
		<script src="js/xbddai.js"></script>
		<script src="js/base.js"></script>
		<script src="js/51size.js"></script>
	</head>
	<body>
		<!--头部开始-->
		<header class="clearfix">
			<div class="header clearfix">
				<ul>
					<li>
						<a href="login.html">
							<i class="iconfont left-icon">&#xe64c;</i>
							<em>返回</em>
						</a>
					</li>
					<li>注册</li>
				</ul>
			</header>
		</header>
		<!--头部结束-->
		
		 <!--主体   开始-->
		 <main>
		 	<div class="register clearfix">
		 		<span class="register-user clearfix">
		 			<em class="phone register-tab">手机注册</em>
		 			<!-- <em class="mell ">邮箱注册</em> -->
		 		</span>
				<dl class="register-switch-begin">
					<dd class="register-base register-switch">
			 			<div class="register-information clearfix">
				 			<ul>
					 			<li>
					 				<div>手机号</div>
					 				<div>
					 					<input type="text" placeholder="请输入手机号" id="phone"/>
					 				</div>
					 			</li>
					 			<li>
					 				<div>验证码</div>
					 				<div>
					 					<input type="text" placeholder="请输入您收到的验证码" id="code"/>
					 					<!--<span>点击发送验证码</span>-->
										<span class="msgs" id="getCode">获取短信验证码</span>
					 				</div>
					 			</li>
					 			<li>
					 				<div>密码</div>
					 				<div>
					 					<input type="password" placeholder="请设置密码（6-20个字符）" id="pwd"/>
					 				</div>
					 			</li>
					 			<li>
					 				<div>确认密码</div>
					 				<div>
					 					<input type="password" placeholder="请再次输入密码" id="qrpwd"/>
					 				</div>
					 			</li>
					 			<li>
					 				<div>推荐码</div>
					 				<div>
					 					<input type="text" placeholder="如果有,请输入推荐码" id="inviteCode"/>
					 				</div>
					 			</li>					 			
					 		</ul>
				 		</div>
				 		<div class="register-footer">
				 			<div class="agreement">
				 				<input type="checkbox" id="agreement" />
				 				<label for="agreement">阅读并同意《用户协议》，接受并遵守注册条款</label>
		
				 			</div>
				 			<div class="register-btn">
				 				<input type="button" value="注册" class="btn1"/>
				 			</div>
				 			<span>已有账号？<a href="login.html">立即登录</a></span>
				 		</div>
			 		</dd>
				</dl>
		 	</div>
		 </main>
		 <!--主体   结束-->
	</body>
<script>
$(function() {
	var hash=window.location.hash;
	hash=hash.replace("#", "");
	if(hash!=''){

		$("#inviteCode").val(hash);
		$("#inviteCode").attr('readonly','readonly');
	}
	$(".yanz button").click(function() {
		$(this).css("background-color", "#ccc")
	})
	$(".btn1").click(function(event) {
		var phone = $("#phone").val();
		var code = $("#code").val();
		var pwd = $("#pwd").val();
		var qrpwd = $("#qrpwd").val();
		var inviteCode=$("#inviteCode").val();
		var reg = /^(((1[0-9][0-9]{1})|159|153)+\d{8})$/;
		if (!reg.test(phone)) {
			alert("请正确填入手机号!");
			return false;
		}
		if (code == '') {
			alert("请输入验证码!");
			return false;
		}
		if (pwd != qrpwd) {
			alert("两次输入的新密码不一致!");
			return false;
		}
		if(!$("input[type='checkbox']").is(':checked')){
			alert('阅读并同意《用户协议》，接受并遵守注册条款!');
			return false;
		}

		var randomCode = localStorage.getItem('randomCode');
		var info = {
			phone: phone,
			password: pwd,
			code: code,
			randomCode: randomCode,
			inviteCode: inviteCode,
			terminal:'WX'
		};
		$.ajax({
			type: 'post',
			dataType: 'JSON',
			async: false,
			url: baseUrl + "/app/register",
			data:info,
			success: function(result) {
				var msg = result["msg"];
				var code = result["code"];
				console.log(result);
				if (code == '-1') {
					alert('注册成功!');
					localStorage.removeItem('randomCode');
					//window.location.href = "login.html";
					var info1 = {
						username: $("#phone").val(),
						password: $("#pwd").val()
					};
					$.ajax({
						type: 'post',
						dataType: 'JSON',
						async: false,
						url: baseUrl + "/app/login",
						data: info1,
						success: function(result) {
							var code = result["code"];
							var msg = result["msg"];
							console.log(result);
							if (code == '-1') {
								var personal = JSON.stringify({
									uid: result['entity']["uid"],
									login_phone: result['entity']["phone"],
									isnew: result['entity']["isnew"]
								});
								localStorage.setItem("personal", personal);
								window.location.href = "my-account.html";
							}
						}
					});
				} else {
					alert(msg);
				}
			}
		});
		event.stopPropagation();
	})
	/*    获取验证码*/
	$("#getCode").click(function(event) {
		if ($(this).hasClass('msgs1')) {
			return false;
		}
		var phone = $("#phone").val();
		var reg = /^(((1[0-9][0-9]{1})|159|153)+\d{8})$/;
		if (!reg.test(phone)) {
			alert("请正确填入手机号!");
			return false;
		}
		var info = {
			phone: phone
		};
		$.ajax({
			type: 'post',
			dataType: 'JSON',
			async: false,
			url: baseUrl + "/app/sms/send",
			data: info,
			success: function(result) {
				var code = result["code"];
				if (code == '-1') {
					localStorage.setItem('randomCode', result['entity']["randomCode"]);
					timedCount();
					alert('获取验证码成功!');
					event.stopPropagation();
				} else {
					alert(result["msg"]);
				}
			}
		});
	});
	/*    获取验证码结束*/
});
var validCode=true;
function timedCount () {
	var time=60	;
	var code=$("#getCode");
	if (validCode) {
		validCode=false;
		code.addClass("msgs1");
		var t=setInterval(function  () {
			time--;
			code.html(time+"秒");
			if (time==0) {
				clearInterval(t);
				code.html("重新获取");
				validCode=true;
				code.removeClass("msgs1");
			}
		},1000)
	}
}
</script>
</html>
